#! /usr/bin/perl
use strict;
use warnings FATAL => 'all';
use utf8;

# calc the average of input nums
sub average {
    my $sum = 0.0;
    foreach (@_) {
        chomp($_);
        $sum = $sum + $_;
    }

    if( 0 == @_) {
        0
    } else {
        $sum / (@_)
    }
}

# figure out the nums larger than the average of input
sub above_average {
    my @larger;
    my $avg = &average(@_);
    foreach (@_) {
        if($_ > $avg) {
            push(@larger, $_);
        }
    }
    @larger
}


my @nums = (1.1, 2.1, 3.1, 1.1, 1.1, 2.1);
print "@nums \n";
print "avg: " . &average(@nums) . "\n";
my @above = &above_average(@nums);
print "@{above}";
